package com.fpx.order.plat.bussiness.service.log.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fpx.order.plat.bussiness.dao.log.IOrderSynclogDao;
import com.fpx.order.plat.bussiness.service.log.IOrderSyncService;
import com.fpx.order.plat.bussiness.vo.OrderSynclogVo;
import com.fpx.order.plat.web.utils.PageUtil;

@Service("orderSyncService")
public class OrderSyncServiceImpl implements IOrderSyncService{
	
	@Autowired
	private IOrderSynclogDao orderSynclogDao;
	
	@Override
	public Map<String, Object> findsyncOrderlogPage(Map<String, Object> map)
			throws Exception {
		if(map==null){
			throw new Exception("分页请求参数不能为空");
		}
		try{
			if(!StringUtils.isNumeric((String)map.get("page"))||
					!StringUtils.isNumeric((String)map.get("rows"))){
				throw new Exception("分页参数page,rows只能为数字");
			}
		}catch(Exception e){
			throw new Exception("分页请求参数不正确");
		}
		//当前页
		int page=Integer.parseInt((String)map.get("page"));
		//每页行数
		int rows=Integer.parseInt((String)map.get("rows"));
		//开始查询的行数
		int start_no=PageUtil.getStartNo(page, rows);
		map.put("start_no", String.valueOf(start_no));
		//结束查询的行数
		int end_no=PageUtil.getEndNo(rows, start_no);
		map.put("end_no", String.valueOf(end_no));
		
		//根据条件分页查询数据
		List<OrderSynclogVo> originOrderLst=orderSynclogDao.findPageSyncOrderLog(map);
		//根据条件查询总行数
		int records=orderSynclogDao.findCountSyncOrderLog(map);
		map.put("rows", originOrderLst);//变成数据集了
		map.put("records", records);//总行数
		map.put("total",PageUtil.getPageSize(records, rows));//总页数
		return map;
	}

}

